home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993 April: Penguin on DISC / ADC Developer CD (1993-04) (''Penguin On DISC'')_iso / Dev.CD Apr 93.iso / Utilities / MPW Interfaces 7.1 Beta / CIncludes / Sound.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-08-28  |  14.1 KB  |  515 lines  |  [TEXT/MPS ]

  1.  
  2. /************************************************************
  3.  
  4. Created: Saturday, July 27, 1991 at 6:48 PM
  5.  Sound.h
  6.  C Interface to the Macintosh Libraries
  7.  
  8.  
  9.   Copyright Apple Computer, Inc. 1986-1991
  10.   All rights reserved
  11.  
  12. *** Warning: This is an alpha version of the Interfaces for Cube-E. 
  13. ***          Things may change.  Caveat Programmer.
  14.  
  15.  
  16. */
  17.  
  18.  
  19. #ifndef __SOUND__
  20. #define __SOUND__
  21.  
  22. #ifndef __TYPES__
  23. #include <Types.h>
  24. #endif
  25.  
  26. #ifndef __FILES__
  27. #include <Files.h>
  28. #endif
  29.  
  30.  
  31. enum {
  32.  
  33.  swMode = -1,                                /* Sound Driver modes */
  34.  ftMode = 1,
  35.  ffMode = 0,
  36.  
  37.  
  38. #define synthCodeRsrc 'snth'                /* Resource types used by Sound Manager */
  39. #define soundListRsrc 'snd '
  40.  
  41. #define twelfthRootTwo 1.05946309434
  42.  
  43.  rate22khz = 0x56EE8BA3,                    /* 22254.54545 in fixed-point */
  44.  rate11khz = 0x2B7745D1,                    /* 11127.27273 in fixed-point */
  45.  
  46. /* synthesizer numbers for SndNewChannel */
  47.  squareWaveSynth = 1,                        /*square wave synthesizer*/
  48.  waveTableSynth = 3,                        /*wave table synthesizer*/
  49.  sampledSynth = 5,                            /*sampled sound synthesizer*/
  50.  
  51. /* old Sound Manager MACE synthesizer numbers */
  52.  MACE3snthID = 11,
  53.  MACE6snthID = 13,
  54.  
  55. /* command numbers for SndDoCommand and SndDoImmediate */
  56.  nullCmd = 0,
  57.  initCmd = 1,
  58.  freeCmd = 2,
  59.  quietCmd = 3,
  60.  flushCmd = 4,
  61.  reInitCmd = 5,
  62.  
  63.  waitCmd = 10,
  64.  pauseCmd = 11,
  65.  resumeCmd = 12,
  66.  callBackCmd = 13
  67. };
  68. enum {
  69.  syncCmd = 14,
  70.  emptyCmd = 15,
  71.  
  72.  tickleCmd = 20,
  73.  requestNextCmd = 21,
  74.  howOftenCmd = 22,
  75.  wakeUpCmd = 23,
  76.  availableCmd = 24,
  77.  versionCmd = 25,
  78.  totalLoadCmd = 26,
  79.  loadCmd = 27,
  80.  
  81.  scaleCmd = 30,
  82.  tempoCmd = 31,
  83.  
  84.  freqDurationCmd = 40,
  85.  restCmd = 41,
  86.  freqCmd = 42,
  87.  ampCmd = 43,
  88.  timbreCmd = 44,
  89.  getAmpCmd = 45,
  90.  
  91.  waveTableCmd = 60,
  92.  phaseCmd = 61
  93. };
  94. enum {
  95.  
  96.  soundCmd = 80,
  97.  bufferCmd = 81,
  98.  rateCmd = 82,
  99.  continueCmd = 83,
  100.  doubleBufferCmd = 84,
  101.  getRateCmd = 85,
  102.  
  103.  sizeCmd = 90,
  104.  convertCmd = 91,
  105.  
  106.  stdQLength = 128,
  107.  dataOffsetFlag = 0x8000,
  108.  
  109.  waveInitChannelMask = 0x07,
  110.  waveInitChannel0 = 0x04,
  111.  waveInitChannel1 = 0x05,
  112.  waveInitChannel2 = 0x06,
  113.  waveInitChannel3 = 0x07,
  114.  
  115. /* channel initialization parameters */
  116.  initPanMask = 0x0003,                        /* mask for right/left pan values */
  117.  initSRateMask = 0x0030,                    /* mask for sample rate values */
  118.  initStereoMask = 0x00C0,                    /* mask for mono/stereo values */
  119.  initCompMask = 0xFF00,                        /* mask for compression IDs */
  120.  
  121.  initChanLeft = 0x0002                        /* left stereo channel */
  122. };
  123. enum {
  124.  initChanRight = 0x0003,                    /* right stereo channel */
  125.  initNoInterp = 0x0004,                        /* no linear interpolation */
  126.  initNoDrop = 0x0008,                        /* no drop-sample conversion */
  127.  initMono = 0x0080,                            /* monophonic channel */
  128.  initStereo = 0x00C0,                        /* stereo channel */
  129.  initMACE3 = 0x0300,                        /* MACE 3:1 */
  130.  initMACE6 = 0x0400,                        /* MACE 6:1 */
  131.  
  132.  initChan0 = 0x0004,                        /* channel 0 - wave table only */
  133.  initChan1 = 0x0005,                        /* channel 1 - wave table only */
  134.  initChan2 = 0x0006,                        /* channel 2 - wave table only */
  135.  initChan3 = 0x0007,                        /* channel 3 - wave table only */
  136.  
  137.  stdSH = 0x00,                                /* Standard sound header encode value */
  138.  extSH = 0xFF,                                /* Extended sound header encode value */
  139.  cmpSH = 0xFE,                                /* Compressed sound header encode value */
  140.  
  141.  notCompressed = 0,                            /* compression ID's */
  142.  twoToOne = 1,
  143.  eightToThree = 2,
  144.  threeToOne = 3,
  145.  sixToOne = 4,
  146.  
  147.  outsideCmpSH = 0                            /* MACE constants */
  148. };
  149. enum {
  150.  insideCmpSH = 1,
  151.  aceSuccess = 0,
  152.  aceMemFull = 1,
  153.  aceNilBlock = 2,
  154.  aceBadComp = 3,
  155.  aceBadEncode = 4,
  156.  aceBadDest = 5,
  157.  aceBadCmd = 6,
  158.  sixToOnePacketSize = 8,
  159.  threeToOnePacketSize = 16,
  160.  stateBlockSize = 64,
  161.  leftOverBlockSize = 32,
  162.  
  163.  firstSoundFormat = 0x0001,                    /* general sound format */
  164.  secondSoundFormat = 0x0002,                /* special sampled sound format (HyperCard) */
  165.  
  166.  dbBufferReady = 0x00000001,                /* double buffer is filled */
  167.  dbLastBuffer = 0x00000004,                    /* last double buffer to play */
  168.  
  169.  sysBeepDisable = 0x0000,                    /* SysBeep() enable flags */
  170.  sysBeepEnable = 0x0001,
  171.  
  172.  unitTypeNoSelection = 0xFFFF,                /* unitTypes for AudioSelection.unitType */
  173.  unitTypeSeconds = 0x0000
  174. };
  175.  
  176.  
  177. /*   Structures for Sound Driver   */
  178.  
  179.  
  180. typedef unsigned char FreeWave[30001];
  181.  
  182. struct FFSynthRec {
  183.  short mode;
  184.  Fixed count;
  185.  FreeWave waveBytes;
  186. };
  187.  
  188. typedef struct FFSynthRec FFSynthRec;
  189. typedef FFSynthRec *FFSynthPtr;
  190.  
  191. struct Tone {
  192.  short count;
  193.  short amplitude;
  194.  short duration;
  195. };
  196.  
  197. typedef struct Tone Tone;
  198.  
  199.  
  200. typedef Tone Tones[5001];
  201.  
  202. struct SWSynthRec {
  203.  short mode;
  204.  Tones triplets;
  205. };
  206.  
  207. typedef struct SWSynthRec SWSynthRec;
  208. typedef SWSynthRec *SWSynthPtr;
  209.  
  210.  
  211. typedef unsigned char Wave[256];
  212. typedef Wave *WavePtr;
  213.  
  214. struct FTSoundRec {
  215.  short duration;
  216.  Fixed sound1Rate;
  217.  long sound1Phase;
  218.  Fixed sound2Rate;
  219.  long sound2Phase;
  220.  Fixed sound3Rate;
  221.  long sound3Phase;
  222.  Fixed sound4Rate;
  223.  long sound4Phase;
  224.  WavePtr sound1Wave;
  225.  WavePtr sound2Wave;
  226.  WavePtr sound3Wave;
  227.  WavePtr sound4Wave;
  228. };
  229.  
  230. typedef struct FTSoundRec FTSoundRec;
  231. typedef FTSoundRec *FTSndRecPtr;
  232.  
  233. struct FTSynthRec {
  234.  short mode;
  235.  FTSndRecPtr sndRec;
  236. };
  237.  
  238. typedef struct FTSynthRec FTSynthRec;
  239. typedef FTSynthRec *FTSynthPtr;
  240.  
  241.  
  242. typedef pascal void (*SndCompletionProcPtr)(void);
  243.  
  244. /*   Structures for Sound Manager   */
  245.  
  246. struct SndCommand {
  247.  unsigned short cmd;
  248.  short param1;
  249.  long param2;
  250. };
  251.  
  252. typedef struct SndCommand SndCommand;
  253.  
  254.  
  255. typedef long Time;                            /* in half milliseconds */
  256.  
  257.  
  258.  
  259. typedef struct SndChannel SndChannel;
  260. typedef SndChannel *SndChannelPtr;
  261.  
  262.  
  263. typedef pascal void (*SndCallBackProcPtr)(SndChannelPtr chan, SndCommand cmd);
  264.  
  265. struct SndChannel {
  266.     struct SndChannel *nextChan;
  267.     Ptr firstMod;                              /* reserved for the Sound Manager */
  268.     SndCallBackProcPtr callBack;
  269.     long userInfo;
  270.     Time wait;                                 /* The following is for internal Sound Manager use only.*/
  271.     SndCommand cmdInProgress;
  272.     short flags;
  273.     short qLength;
  274.     short qHead;                               /* next spot to read or -1 if empty */
  275.     short qTail;                               /* next spot to write = qHead if full */
  276.     SndCommand queue[stdQLength];
  277. };
  278.  
  279. /* MACE structures */
  280. struct StateBlock {
  281.  short stateVar[stateBlockSize];
  282. };
  283.  
  284. typedef struct StateBlock StateBlock;
  285. typedef StateBlock *StateBlockPtr;
  286.  
  287. struct LeftOverBlock {
  288.  unsigned long count;
  289.  char sampleArea[leftOverBlockSize];
  290. };
  291.  
  292. typedef struct LeftOverBlock LeftOverBlock;
  293. typedef LeftOverBlock *LeftOverBlockPtr;
  294.  
  295. struct ModRef {
  296.  unsigned short modNumber;
  297.  long modInit;
  298. };
  299.  
  300. typedef struct ModRef ModRef;
  301.  
  302. struct SndListResource {
  303.  short format;
  304.  short numModifiers;
  305.  ModRef modifierPart[1];                    /*This is a variable length array*/
  306.  short numCommands;
  307.  SndCommand commandPart[1];                    /*This is a variable length array*/
  308.  char dataPart[1];                            /*This is a variable length array*/
  309. };
  310.  
  311. typedef struct SndListResource SndListResource;
  312. typedef SndListResource *SndListPtr;
  313.  
  314. struct SoundHeader {
  315.  Ptr samplePtr;                                /* if NIL then samples are in sampleArea */
  316.  unsigned long length;                        /* length of sound in bytes */
  317.  Fixed sampleRate;                            /* sample rate for this sound */
  318.  unsigned long loopStart;                    /* start of looping portion */
  319.  unsigned long loopEnd;                        /* end of looping portion */
  320.  unsigned char encode;                        /* header encoding */
  321.  unsigned char baseFrequency;                /* baseFrequency value */
  322.  char sampleArea[1];
  323. };
  324.  
  325. typedef struct SoundHeader SoundHeader;
  326. typedef SoundHeader *SoundHeaderPtr;
  327.  
  328. struct CmpSoundHeader {
  329.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  330.  unsigned long numChannels;                    /* number of channels i.e. mono = 1 */
  331.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  332.  unsigned long loopStart;                    /* loopStart of sound before compression */
  333.  unsigned long loopEnd;                        /* loopEnd of sound before compression */
  334.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  335.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  336.  unsigned long numFrames;                    /* length in frames ( packetFrames or sampleFrames ) */
  337.  extended80     AIFFSampleRate;                /* IEEE sample rate */
  338.  Ptr markerChunk;                            /* sync track */
  339.  Ptr futureUse1;                            /* reserved by Apple */
  340.  Ptr futureUse2;                            /* reserved by Apple */
  341.  StateBlockPtr stateVars;                    /* pointer to State Block */
  342.  LeftOverBlockPtr leftOverSamples;            /* used to save truncated samples between compression calls */
  343.  unsigned short compressionID;                /* 0 means no compression, non zero means compressionID */
  344.  unsigned short packetSize;                    /* number of bits in compressed sample packet */
  345.  unsigned short snthID;                        /* resource ID of Sound Manager snth that contains NRT C/E */
  346.  unsigned short sampleSize;                    /* number of bits in non-compressed sample */
  347.  char sampleArea[1];                        /* space for when samples follow directly */
  348. };
  349.  
  350. typedef struct CmpSoundHeader CmpSoundHeader;
  351. typedef CmpSoundHeader *CmpSoundHeaderPtr;
  352.  
  353. struct ExtSoundHeader {
  354.  Ptr samplePtr;                                /* if nil then samples are in sample area */
  355.  unsigned long numChannels;                    /* number of channels,  ie mono = 1 */
  356.  Fixed sampleRate;                            /* sample rate in Apples Fixed point representation */
  357.  unsigned long loopStart;                    /* same meaning as regular SoundHeader */
  358.  unsigned long loopEnd;                        /* same meaning as regular SoundHeader */
  359.  unsigned char encode;                        /* data structure used , stdSH, extSH, or cmpSH */
  360.  unsigned char baseFrequency;                /* same meaning as regular SoundHeader */
  361.  unsigned long numFrames;                    /* length in total number of frames */
  362.  extended80 AIFFSampleRate;                    /* IEEE sample rate */
  363.  Ptr markerChunk;                            /* sync track */
  364.  Ptr instrumentChunks;                        /* AIFF instrument chunks */
  365.  Ptr AESRecording;
  366.  unsigned short sampleSize;                    /* number of bits in sample */
  367.  unsigned short futureUse1;                    /* reserved by Apple */
  368.  unsigned long futureUse2;                    /* reserved by Apple */
  369.  unsigned long futureUse3;                    /* reserved by Apple */
  370.  unsigned long futureUse4;                    /* reserved by Apple */
  371.  char sampleArea[1];                        /* space for when samples follow directly */
  372. };
  373.  
  374. typedef struct ExtSoundHeader ExtSoundHeader;
  375. typedef ExtSoundHeader *ExtSoundHeaderPtr;
  376.  
  377. struct ConversionBlock {
  378.  short destination;
  379.  short unused;
  380.  CmpSoundHeaderPtr inputPtr;
  381.  CmpSoundHeaderPtr outputPtr;
  382. };
  383.  
  384. typedef struct ConversionBlock ConversionBlock;
  385. typedef ConversionBlock *ConversionBlockPtr;
  386.  
  387. struct SMStatus {
  388.  short smMaxCPULoad;
  389.  short smNumChannels;
  390.  short smCurCPULoad;
  391. };
  392.  
  393. typedef struct SMStatus SMStatus;
  394. typedef SMStatus *SMStatusPtr;
  395.  
  396. struct SCStatus {
  397.  Fixed scStartTime;
  398.  Fixed scEndTime;
  399.  Fixed scCurrentTime;
  400.  Boolean scChannelBusy;
  401.  Boolean scChannelDisposed;
  402.  Boolean scChannelPaused;
  403.  Boolean scUnused;
  404.  unsigned long scChannelAttributes;
  405.  long scCPULoad;
  406. };
  407.  
  408. typedef struct SCStatus SCStatus;
  409. typedef SCStatus *SCStatusPtr;
  410.  
  411. struct AudioSelection {
  412.  long unitType;
  413.  Fixed selStart;
  414.  Fixed selEnd;
  415. };
  416.  
  417. typedef struct AudioSelection AudioSelection;
  418. typedef AudioSelection *AudioSelectionPtr;
  419.  
  420. struct SndDoubleBuffer {
  421.  long dbNumFrames;
  422.  long dbFlags;
  423.  long dbUserInfo[2];
  424.  char dbSoundData[1];
  425. };
  426.  
  427. typedef struct SndDoubleBuffer SndDoubleBuffer;
  428. typedef SndDoubleBuffer *SndDoubleBufferPtr;
  429.  
  430.  
  431. typedef pascal void (*SndDoubleBackProcPtr) (SndChannelPtr channel,
  432.            SndDoubleBufferPtr doubleBufferPtr);
  433.  
  434. struct SndDoubleBufferHeader {
  435.  short dbhNumChannels;
  436.  short dbhSampleSize;
  437.  short dbhCompressionID;
  438.  short dbhPacketSize;
  439.  Fixed dbhSampleRate;
  440.  SndDoubleBufferPtr dbhBufferPtr[2];
  441.  SndDoubleBackProcPtr dbhDoubleBack;
  442. };
  443.  
  444. typedef struct SndDoubleBufferHeader SndDoubleBufferHeader;
  445. typedef SndDoubleBufferHeader *SndDoubleBufferHeaderPtr;
  446.  
  447.  
  448. #ifdef __cplusplus
  449. extern "C" {
  450. #endif
  451. pascal OSErr SndDoCommand(SndChannelPtr chan,const SndCommand *cmd,Boolean noWait)
  452.  = 0xA803; 
  453. pascal OSErr SndDoImmediate(SndChannelPtr chan,const SndCommand *cmd)
  454.  = 0xA804; 
  455. pascal OSErr SndNewChannel(SndChannelPtr *chan,short synth,long init,SndCallBackProcPtr userRoutine)
  456.  = 0xA807; 
  457. pascal OSErr SndDisposeChannel(SndChannelPtr chan,Boolean quietNow)
  458.  = 0xA801; 
  459. pascal OSErr SndPlay(SndChannelPtr chan,Handle sndHdl,Boolean async)
  460.  = 0xA805; 
  461. pascal OSErr SndAddModifier(SndChannelPtr chan,ProcPtr modifier,short id,
  462.  long init)
  463.  = 0xA802; 
  464. pascal OSErr SndControl(short id,SndCommand *cmd)
  465.  = 0xA806; 
  466.  
  467. pascal void SetSoundVol(short level); 
  468. #pragma parameter GetSoundVol(__A0)
  469. pascal void GetSoundVol(short *level)
  470.  = {0x4218,0x10B8,0x0260}; 
  471. pascal void StartSound(const void *synthRec,long numBytes,SndCompletionProcPtr completionRtn); 
  472. pascal void StopSound(void); 
  473. pascal Boolean SoundDone(void); 
  474.  
  475. pascal NumVersion SndSoundManagerVersion(void)
  476.  = {0x203C,0x000C,0x0008,0xA800}; 
  477. pascal OSErr SndStartFilePlay(SndChannelPtr chan,short fRefNum,short resNum,
  478.  long bufferSize,void *theBuffer,AudioSelectionPtr theSelection,ProcPtr theCompletion,
  479.  Boolean async)
  480.  = {0x203C,0x0D00,0x0008,0xA800}; 
  481. pascal OSErr SndPauseFilePlay(SndChannelPtr chan)
  482.  = {0x203C,0x0204,0x0008,0xA800}; 
  483. pascal OSErr SndStopFilePlay(SndChannelPtr chan,Boolean async)
  484.  = {0x203C,0x0308,0x0008,0xA800}; 
  485. pascal OSErr SndChannelStatus(SndChannelPtr chan,short theLength,SCStatusPtr theStatus)
  486.  = {0x203C,0x0010,0x0008,0xA800}; 
  487. pascal OSErr SndManagerStatus(short theLength,SMStatusPtr theStatus)
  488.  = {0x203C,0x0014,0x0008,0xA800}; 
  489. pascal void SndGetSysBeepState(short *sysBeepState)
  490.  = {0x203C,0x0018,0x0008,0xA800}; 
  491. pascal OSErr SndSetSysBeepState(short sysBeepState)
  492.  = {0x203C,0x001C,0x0008,0xA800}; 
  493. pascal OSErr SndPlayDoubleBuffer(SndChannelPtr chan,SndDoubleBufferHeaderPtr theParams)
  494.  = {0x203C,0x0020,0x0008,0xA800}; 
  495.  
  496. pascal NumVersion MACEVersion(void)
  497.  = {0x203C,0x0000,0x0010,0xA800}; 
  498. pascal void Comp3to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  499.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  500.  = {0x203C,0x0004,0x0010,0xA800}; 
  501. pascal void Exp1to3(const void *inBuffer,void *outBuffer,unsigned long cnt,
  502.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  503.  = {0x203C,0x0008,0x0010,0xA800}; 
  504. pascal void Comp6to1(const void *inBuffer,void *outBuffer,unsigned long cnt,
  505.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  506.  = {0x203C,0x000C,0x0010,0xA800}; 
  507. pascal void Exp1to6(const void *inBuffer,void *outBuffer,unsigned long cnt,
  508.  const void *inState,void *outState,unsigned long numChannels,unsigned long whichChannel)
  509.  = {0x203C,0x0010,0x0010,0xA800}; 
  510. #ifdef __cplusplus
  511. }
  512. #endif
  513.  
  514. #endif
  515.